﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using QuanLiNhaSachDAO;
using QuanLiNhaSachDTO;

namespace QuanLiNhaSachBUS
{
    public class NhaCungCapBUS
    {
        public static DataTable SelectAll()
        {
            try
            {
                return NhaCungCapDAO.selectAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi load");
            }
            return null;
        }

        public static void Insert(NhaCungCap m)
        {
            try
            {
                NhaCungCapDAO.insert(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi thêm");
            }
        }

        public static void Update(NhaCungCap m)
        {
            try
            {
                NhaCungCapDAO.update(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi chỉnh sửa");
            }
        }

        public static void Delete(NhaCungCap q)
        {
            try
            {
                NhaCungCapDAO.delete(q);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi xóa");
            }
        }

        public static NhaCungCap search(string id)
        {
            try
            {
                NhaCungCap tl = new NhaCungCap();
                DataTable dt = NhaCungCapDAO.search(id);
                tl.Id = dt.Rows[0]["id"].ToString();
                tl.Ten = dt.Rows[0]["Ten"].ToString();
                tl.Email = dt.Rows[0]["Email"].ToString();
                tl.DiaChi = dt.Rows[0]["DiaChi"].ToString();
                tl.DienThoai = dt.Rows[0]["DienThoai"].ToString();
                tl.GhiChu = dt.Rows[0]["GhiChu"].ToString();
                return tl;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm kiếm");
            }
            return null;
        }
        public static DataTable TimSachTuNhaCungCap(string id)
        {
            try
            {
                return NhaCungCapDAO.TimSachTuNhaCungCap(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm sách");
            }
            return null;
        }
    }
}
